package playn.game.core;

import java.util.ArrayList;
import java.util.Iterator;

import playn.game.entities.Sonic;

import tiled.simple.core.MapObject;
import tiled.simple.core.TMXObjectsProvider;

public class MapObjectsProvider implements TMXObjectsProvider {
	private Game game;

	public Sonic hero;
		
	public MapObjectsProvider(Game game) {
		this.game=game;
	}

	ArrayList<Entity> entities = new ArrayList<Entity>();
	
	public void object(MapObject mapObject) {
		
		if(mapObject.getType().equalsIgnoreCase("Hero")&&(!Game.initialized)){
			hero=new Sonic(game,mapObject);
			entities.add(hero);
		}
	}
	
	public void render(){
		Iterator<Entity> itr=entities.iterator();
		while (itr.hasNext()) {
			Entity entity=itr.next();
			entity.render();
		}
	}

	public void update(float delta){
		Iterator<Entity> itr=entities.iterator();
		while (itr.hasNext()) {
			Entity entity=itr.next();
			entity.update(delta);
		}
	}

}
